package model;

import java.io.File;
import javax.swing.JFrame;
import network.UdpClient;
import physics.PhysicsEngine;
import view.GameView;
import utility.Utility;

/**
 * This Game will 
 * 
 * @author juice
 */
public class Game extends JFrame {

	private GameView gameView;
	private PhysicsEngine physicsEngine;
	private UdpClient client;
	public static int id = 0;
	public static String ip = "129.16.78.188";
	private static Game instance;

	private Game(){

		//id = World.getInstance().getMyID();
		//ip = World.getInstance().getServerIP();
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);

		World.getInstance().setLevel(new Level(Utility.readMapFile(new File("maps//map0.txt"))));
		gameView = GameView.getInstance();
		add(gameView);
		pack();

		physicsEngine = PhysicsEngine.getInstance();
		physicsEngine.start(1000/30);

		client = new UdpClient(id, ip);
		client.start(1000/15);

		gameView.start(1000/30);

	}

	public static Game getInstance(){
		if(instance == null){
			instance = new Game();
		}
		return instance;
	}


	public void setId(int id) {
		Game.id = id;
	}

	public int getId() {
		return id;
	}

	public void setGameView(GameView gameView) {
		this.gameView = gameView;
	}

	public GameView getGameView() {
		return gameView;
	}

}
